﻿<#
.SYNOPSIS  
    Performs a SharePoint 2007 upgrade on a SharePoint 2010 farm using the database attach or hybrid approach.  
    This script must be run as the SharePoint 2010 farm account.  
.DESCRIPTION  
    This script executes the upgrade sequence in the correct order using configuration information in the Upgrade.xml file.
    You can schedule this script to run on a periodic basis to practice upgrade.  When scheduling upgrade, the sequence should be
    TearDown-Farm.ps1, SQL job to backup and restore SharePoint 2007 databases, Upgrade-Farm.ps1. 
    After upgrade, you should review the following log files for errors:
        Upgrade-Farm.log
        Get-UpgradeErrors.xml
        localupgradestatus.txt
.NOTES
    Pre-conditions:
       -Upgrade.xml contains correct configuration (dev / prod / sat, managed accounts, database servers, database names etc)
       -SharePoint 2010 and other bits to be upgraded such as Project Server are installed
       -The SharePoint 2010 farm has been created
       -Managed account(s) referenced in Upgrade.xml have been created
       -Databases referenced in Upgrade.xml have been restored to SQL
       -This script should be run as the SharePoint farm account to ensure correct database ownership
.LINK  
    http://7up.codeplex.com
#>

#gets the script directory
function Get-ScriptDirectory
{
	$Invocation = (Get-Variable MyInvocation -Scope 1).Value
	Split-Path $Invocation.MyCommand.Path
}

#set current directory
cd (Get-ScriptDirectory)

Start-Transcript -Path ".\Upgrade-Farm.log"

Write-Host ("Upgrading the farm ({0})..." -f [DateTime]::Now.ToString())

#remove old upgrade log files
.\Remove-UpgradeLogFiles

#create web apps
.\Add-WebApplications

#add additional IIS Bindings
.\Add-IISBindings

#add entries to hosts file
.\Add-HostsFileEntries

#install and deploy custom solutions
.\Add-Solutions

#upgrade content databases
.\Add-ContentDatabases

#add profile service applications (upgrade MOSS SSPs)
.\Add-ProfileServiceApplications

#add project service applications
.\Add-ProjectServiceApplications

#add project web instances (upgrade Project Server 2007)
.\Add-ProjectWebInstances

#enable web app features
.\Enable-WebApplicationFeatures

#execute post upgrade actions
.\Execute-PostUpgradeActions

#get upgrade errors
.\Get-UpgradeErrors

#get upgrade status
stsadm -o localupgradestatus > .\localupgradestatus.txt

Write-Host ("Farm upgrade complete ({0})..." -f [DateTime]::Now.ToString())

Stop-Transcript

#clean up the transcript file (start-transcript doesn't format linebreaks)
[string]::Join("`r`n",(Get-Content ".\Upgrade-Farm.log")) | Out-File ".\Upgrade-Farm.log"